package com.zlzxm.sorting.ui.window

import android.app.Dialog
import android.view.LayoutInflater
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import com.zlzxm.sorting.R
import com.zlzxm.sorting.util.ui.window.AbsWindow

/**
 *
 *CREATE BY zlzxm ON 2022/8/17
 *
 */
class WindowSure private constructor():
    AbsWindow(), View.OnClickListener {

    companion object{


        fun create(title:String,content:String,cancelTitle:String?=null,sureTitle:String?=null): WindowSure {

            val window = WindowSure()
            window.title = title
            window.content = content
            window.cancelTitle = cancelTitle
            window.sureTitle = sureTitle

            return window
        }

    }


    interface OnWindowSureListener{

        fun onWindowSure()

        fun onWindowCancel()
    }

    override fun initRootView(rlRoot: RelativeLayout?) {
        LayoutInflater.from(requireContext()).inflate(

            R.layout.window_sure,rlRoot,true
        )
    }

    var onWindowSureListener : OnWindowSureListener?=null

    var title : String?=null
    var content : String?=null
    var cancelTitle : String?=null
    var sureTitle : String?=null

    override fun initView(dialog: Dialog?) {

        setOutSideTouchDismiss(true)

        title?.let {
            dialog?.findViewById<TextView>(R.id.tvTitle)?.text = it
        }
        content?.let {
            dialog?.findViewById<TextView>(R.id.tvContent)?.text = it
        }
        cancelTitle?.let {
            dialog?.findViewById<TextView>(R.id.tvCancel)?.text = it
        }
        sureTitle?.let {
            dialog?.findViewById<TextView>(R.id.tvSure)?.text = it
        }

        dialog?.findViewById<TextView>(R.id.tvCancel)?.setOnClickListener(this)
        dialog?.findViewById<TextView>(R.id.tvSure)?.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        v?.let {
            when(it.id){

                R.id.tvCancel -> {
                    dismiss()
                    onWindowSureListener?.onWindowCancel()
                }
                R.id.tvSure -> {
                    dismiss()
                    onWindowSureListener?.onWindowSure()
                }

                else -> {

                }
            }


        }

    }

}